package com.tomtop.core.model;

import com.tomtop.core.exception.GlobalException;
import com.tomtop.core.exception.ExceptionLevel;
import com.tomtop.core.exception.ExceptionStatus;
import com.tomtop.core.exception.GlobalExceptionStatus;

public class ResponseEntity<T> {
	private int code;
	private String message;
	private String details;
	private ExceptionLevel level;
	private T entity;

	public ResponseEntity() {
		this(null, null);
	}

	public ResponseEntity(T entity) {
		this(entity, null);
	}

	public ResponseEntity(ExceptionStatus ExceptionStatus) {
		this(null, ExceptionStatus);
	}

	public ResponseEntity(GlobalException customException) {
		this.code = customException.getCode();
		this.message = customException.getDescribe();
		this.details = customException.getDetails();
		this.level = customException.getLevel();
	}

	public ResponseEntity(T entity, ExceptionStatus ExceptionStatus) {
		this.entity = entity;
		if (ExceptionStatus == null)
			ExceptionStatus = GlobalExceptionStatus.OK;
		this.code = ExceptionStatus.getCode();
		this.message = ExceptionStatus.getMessage();
		this.level = ExceptionStatus.getLevel();
	}

	public static <S> ResponseEntity<S> now() {
		return new ResponseEntity<>();
	}

	public static <S> ResponseEntity<S> now(S entity) {
		return new ResponseEntity<>(entity);
	}

	public static <S> ResponseEntity<S> now(GlobalException customException) {
		return new ResponseEntity<>(customException);
	}

	public static <S> ResponseEntity<S> now(S entity, ExceptionStatus ExceptionStatus) {
		return new ResponseEntity<>(entity, ExceptionStatus);
	}

	public static <S> ResponseEntity<S> now(ExceptionStatus ExceptionStatus) {
		return new ResponseEntity<>(ExceptionStatus);
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public ExceptionLevel getLevel() {
		return level;
	}

	public void setLevel(ExceptionLevel level) {
		this.level = level;
	}

}
